package cj.web.portal.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cj.web.kly.domain.Columns;
import cj.web.kly.domain.News;
import cj.web.portal.dao.ColumnsVoDAO;
import cj.web.portal.dao.NewsVoDAO;

@Service
public class ColumnsNewsService {

	@Autowired
    private NewsVoDAO newsVoDAO;
	@Autowired
    private ColumnsVoDAO columnsVoDAO;
	
	/**
	 * 查询栏目信息
	 * @param columnsId
	 * @return
	 */
	public Columns queryColumns(int columnsId){
		return columnsVoDAO.queryById(columnsId);
	}
	
	/**
	 * 相关新闻
	 * @param columnsId
	 * @param start
	 * @param length
	 * @return
	 */
	public List<News> querylis(int columnsId,int start,int length){
		return newsVoDAO.query(columnsId, start, length);
	}
	
	/**
	 * 查询
	 * @param news
	 * @return newslis;size
	 */
	public Map query(int columnsId,String source,int start,int length){
		Map rep = new HashMap();
		List<News> newslis = newsVoDAO.query(columnsId,source, start, length);
		int size = newsVoDAO.querySize(columnsId,source);
		rep.put("newslis", newslis);
		rep.put("size", size);
		return rep;
    }
	
	/**
	 * 
	 * @param id
	 * @return
	 */
	public List<News> queryListById(int columnsId,int id,int start,int length){
		List<News> newslis = newsVoDAO.query(columnsId,id, start, length);
		return newslis;
    }
	
	/**
	 * 
	 * @param id
	 * @return
	 */
	public List<News> queryForContentById(int columnsId,int start,int length){
		List<News> newslis = newsVoDAO.queryForContent(columnsId, start, length);
		return newslis;
    }
	
	public News queryById(int id){
		News obj = newsVoDAO.queryById(id);
		newsVoDAO.addPV(id);
		return obj;
    }
	
	/**
	 * 查询
	 * @param news
	 * @return newslis;size
	 */
	public Map querySearchList(String not_in_news_columnsid,String keywords,int start,int length){
		Map rep = new HashMap();
		List<News> newslis = newsVoDAO.querySearchList(not_in_news_columnsid,keywords, start, length);
		int size = newsVoDAO.querySearchListSize(not_in_news_columnsid,keywords);
		rep.put("newslis", newslis);
		rep.put("size", size);
		return rep;
    }
}